package com.pw.study.web.controller;

import com.pw.study.web.entities.Msg;
import com.pw.study.web.entities.StudentEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @description:
 * @author: linux_future
 * @date: 2022/12/3
 */
@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "super.toString()";
    }

    @GetMapping("/")
    public String index() {
        return "红，去测试主页";
    }

    @PostMapping("/user")
    public String user(@RequestParam("name") String username) {
        return "红，去测试主页-->" + username + " 你好";
    }

    @PostMapping("/user2")
    public String user2(@RequestParam("name") String username,@RequestParam("pwd") String pwd) {
        if(username.equals("zhansan")){
            int n= 10/0;
        }
        return "红，去测试主页-->" + username + " 你好"+"---"+pwd;
    }

    @GetMapping("/tes1")
    public String test1() {
        int n = 10 / 0;
        return "这是一个报错结果";
    }

    @GetMapping("/student")
    public String student() {
        StudentEntity student = new StudentEntity();

        return "这是一个学生，你不知道叫什么" + student;
    }

    @GetMapping("/ok")
    public Msg ok() {
        Msg msg = new Msg();
        msg.setCode(200);
        msg.setStatus("success");
        HashMap<String, Object> map = new HashMap<>();
        map.put("name", "魏红");
        msg.setData(map);

        return msg;
    }
}
